﻿{include file='public/_meta'}

<title>空白页</title>
</head>
<body>

<div class="page-container" style="padding-top:0px;">
    <form action="{:url('admin/qtgl/printbpdo')}" method="post" class="form form-horizontal layui-form" id="form-ctbp-addbp">
        <div class="row cl" style="padding-top:0px;margin-top: 4px;padding-left: 10px;">
        <table id="listTable" class="table table-border table-bordered table-bg table-sort display">
            <thead>
            <tr>
                <th scope="col" colspan="9">订单列表</th>
            </tr>
            <tr>
                <th width="40">ID</th>
                <th width="120">交易日期</th>
                <th>项目编号</th>
                <th>项目名称</th>
                <th width="60">单价</th>
                <th width="60">数量</th>
                <th width="60">金额</th>
                <th width="70">工号</th>
                <th width="70">姓名</th>
            </tr>
            </thead>
            <tfoot>
                <tr>
                    <th colspan="5" align="center" class="text-c">合计</th>
                    <th id="slhj"></th>
                    <th id="jehj"></th>
                    <th></th>
                    <th></th>
                </tr>
            </tfoot>
        </table>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="button" class="btn btn-success radius" id="admin-print-btn" name="admin-print-btn"><i class="icon-ok"></i> 打印已录项目</button>
                <button type="button" class="btn btn-secondary radius" id="admin-close" name="admin-close-save" onclick="closeWindow()"><i class="icon-ok"></i> 关闭窗口</button>
            </div>
        </div>
    </form>
</div>

<div id="printBox" style="display: none;">
    <!--startprint1-->
    <table class="table">
        <tr>
            <td style="font-size: 18px;font-weight: bold;height: 25px;" align="center" class="text-c">
                铁岭市殡仪服务中心
            </td>
        </tr>
        <tr>
            <td height="20" style="font-size: 14px;">操作员：{$userinfo.uname} &nbsp;{$qzrq}</td>
        </tr>
    </table>
    <table class="table table-border table-bordered radius display" id="printxmlist">
        <tr>
            <td colspan="4"></td>
        </tr>
        <thead>
        <tr>
            <th>项目名称</th><th>单价</th><th>数量</th><th>金额</th>
        </tr>
        </thead>
        <tfoot>
        <tr>
            <th colspan="2" class="text-c" align="center">合计</th>
            <th id="print_hjsl"></th>
            <th id="print_hjje"></th>
        </tr>
        <tr>
            <th colspan="4"></th>
        </tr>
        </tfoot>
    </table>
    <table class="table">
        <tr>
            <td>
                存尸位置：{$csinfo.cs_fjid}&nbsp;&nbsp;逝者姓名：{$info.xm}
            </td>
        </tr>
        <tr>
            <td align="center" class="text-c" height="20" style="font-size: 14px;">
                单号：{$info.ddh}
            </td>
        </tr>
        <tr>
            <td align="center" class="text-c" height="20" style="font-size: 14px;">
                在五日内到殡仪服务中心复核
            </td>
        </tr>
    </table>
    <!--endprint1-->
</div>

<!--_footer 作为公共模版分离出去-->
{include file='public/_footer'}
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<!--<script type="text/javascript" src="__PUBLIC__other/jquery1.8.3/jquery.js"></script>-->
<!--<script type="text/javascript" src="__PUBLIC__other/dayin/jquery-1.4.4.min.js"></script>-->
<script type="text/javascript" src="__PUBLIC__lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__PUBLIC__lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__PUBLIC__lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__PUBLIC__lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript">
    var t;

    $(document).ready(function () {
        var total5 = 0;
        var total6 = 0;
        var counter = 1;
        var bplist = {$bplist};
        //console.log(bplist);
        var total5_print = 0;
        var total6_print = 0;
        var counter_print = 1;
        var bplist_print = {$printbplist};
        // 初始化表格数据
        var t = $('#listTable').DataTable({
            "data": bplist,
            "ordering": false, //排序功能
            "paging": false,
            "searching":false,
            "lengthChange":false,
            "info":false,
            "footerCallback": function ( row, data, start, end, display ) {
                var api = this.api(), data;
                // Remove the formatting to get integer data for summation
                var intVal = function ( i ) {
                    return typeof i === 'string' ?
                        i.replace(/[\$,]/g, '')*1 :
                        typeof i === 'number' ?
                            i : 0;
                };
                // 合计项目数量
                total5 = api.columns(5).data().reduce( function ( a, b ) {
                    return intVal(intVal(a) + intVal(b));
                } );
                // 合计金额
                total6 = api.columns(6).data().reduce( function ( a, b ) {
                    return intVal(intVal(a) + intVal(b));
                } );

                // 显示数量
                var t5 = 0;
                $.each(total5,function(index,j){
                    t5 += parseInt(j);
                })
                $( '#slhj').html(t5);
                // 显示金额
                var t6 = 0;
                $.each(total6,function(index,j){
                    t6 += parseInt(j);
                })
                $( '#jehj').html(t6);
            }
        });

        var print_t = $('#printxmlist').DataTable(
            {
                "data": bplist_print,
                "ordering": false, //排序功能
                "paging": false,
                "searching":false,
                "lengthChange":false,
                "info":false,
                "footerCallback": function ( row, data, start, end, display ) {
                    var api = this.api(), data;
                    // Remove the formatting to get integer data for summation
                    var intVal = function ( i ) {
                        return typeof i === 'string' ?
                            i.replace(/[\$,]/g, '')*1 :
                            typeof i === 'number' ?
                                i : 0;
                    };

                    // 合计项目数量
                    var total5_print = api.columns(2).data().reduce( function ( a, b ) {
                        return intVal(intVal(a) + intVal(b));
                    } );
                    // 合计金额
                    var total6_print = api.columns(3).data().reduce( function ( a, b ) {
                        return intVal(intVal(a) + intVal(b));
                    } );

                    // 显示数量
                    var t5 = 0;
                    $.each(total5_print,function(index,j){
                        t5 += parseInt(j);
                    })
                    $( '#print_hjsl').html(t5);
                    // 显示金额
                    var t6 = 0;
                    $.each(total6_print,function(index,j){
                        t6 += parseInt(j);
                    })
                    $( '#print_hjje').html(t6);

                }
            }
        );

        $('#admin-print-btn').on('click',function(){
            preview(1);
        });


    });


    function printxm(oper){
        preview(oper);
    }

    function preview(oper){
        if (oper < 10){
            bdhtml=window.document.body.innerHTML;      //获取当前页的html代码
            sprnstr="<!--startprint"+oper+"-->";        //设置打印开始区域
            eprnstr="<!--endprint"+oper+"-->";          //设置打印结束区域
            prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
            prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); //从结束代码向前取html
            window.document.body.innerHTML=prnhtml;
            window.print();
            window.document.body.innerHTML=bdhtml;
        } else {
            window.print();
        }
    }

    function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
        window.parent.location.reload();
    }
</script>
</body>
</html>